package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.callback.ItemClickedCallback;
import com.cardbaobao.cardbabyclient.model.BankData;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

import java.util.List;

/**
 * Created by Jiangzx on 2017/9/12 14:05.
 */

public class ChooseBankAdapter extends CommonRecyclerAdapter<BankData.Bank> {
    private ItemClickedCallback<BankData.Bank> listener;

    public void setItemClickedCallback(ItemClickedCallback<BankData.Bank> listener){
        this.listener=listener;
    }

    public ChooseBankAdapter(Context context, List<BankData.Bank> data) {
        super(context, data, R.layout.item_choose_bank);
    }

    @Override
    public void convert(CommonRecyclerHolder holder,final BankData.Bank bank) {
        holder.setTextViewText(R.id.tv_bank,bank.getName());
        ImageLoaderUtil.displayImageWithPlaceHolder(
                URLUtil.CBB_IMG_URL+bank.getPicture(),
                (ImageView) holder.getView(R.id.iv_logo),
                R.mipmap.img_default_square);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onItemClicked(bank);
                }
            }
        });
    }

}
